// AppChooserXMLConfigFile.h
// 
// Copyright (c) Jason Sandys, 2009
//
// License: This code is released according to the 
// Microsoft Public License (Ms-PL) as documented at 
// http://osdappchooser.codeplex.com/license
//
//////////////////////////////////////////////////////////////////////

#pragma once
#include "xmlconfigfile.h"

class COSDAppChooserDlg;

#define APPSET_NAMEATTRIBUTE		_T ("name")
#define APPSET_ELEMENTNAME			_T ("AppSet")
#define APPSET_SELECTALLATTRIBUTE	_T ("defaultAll")

#define APPSETS_PROMPTATTRIBUTE		_T ("prompt")
#define APPSETS_ELEMENTNAME			_T ("AppSets")

#define APPGROUP_ELEMENTNAME		_T ("AppGroup")
#define APPGROUP_NAMEATTRIBUTE		_T ("groupName")
#define APPGROUP_MANDATORYATTRIBUTE _T ("mandatory")
#define APPGROUP_DEFAULTATTRIBUTE	_T ("default")

#define APPS_ELEMENTNAME			_T ("Apps")
#define TITLE_ATTRIBUTE				_T ("title")
#define DESCRIPTION_ATTRIBUTE		_T ("description")
#define INFO_ATTRIBUTE				_T ("info")
#define ICON_ATTRIBUTE				_T ("icon")

#define APPREF_ELEMENTNAME			_T ("AppRef")
#define APPREF_IDATTRIBUTE			_T ("appId")
#define APPREF_MANDATORYATTRIBUTE	_T ("mandatory")
#define APPREF_DEFAULTATTRIBUTE		_T ("default")

#define APP_ELEMENTNAME				_T ("App")
#define APP_IDATTRIBUTE				_T ("id")
#define APP_INFOATTRIBUTE			_T ("info")
#define APP_NAMEATTRIBUTE			_T ("name")
#define APP_PROGIDATTRIBUTE			_T ("progID")
#define APP_PKGIDATTRIBUTE			_T ("pkgID")
#define APP_REQUIRESATTRIBUTE		_T ("requires")
#define APP_ICONATTRIBUTE			_T ("icon")


//************************************************************
/**
<summary>Specializes the CjXMLConfigFile class to read and
retrieve information from an XML based configuration file
for OSDAppChooser</summary>
*/
//************************************************************
class CjAppChooserXMLConfigFile :
	public CjXMLConfigFile
{
public:
	CjAppChooserXMLConfigFile(void);
	~CjAppChooserXMLConfigFile(void);
	CString GetAppSetPrompt(void);
	CString GetRootAttribute(const CString& attr, UINT defaultString = 0);
	void GetAppSets (CStringList& lstAppSets, LPCTSTR lpszDefAppSet = 0);
	void GetApps (COSDAppChooserDlg* dlg, LPCTSTR lpszAppSet);
	void ParseAppSet (const XmlElement& eParent, COSDAppChooserDlg* dlg, HTREEITEM hParent = 0, bool bParentDefault = false, bool bParentMandatory = false);
	bool GetAppInfo (long nIndex, CString& strPkgID, CString& strProgID);
	int GetAppIndex (PCTSTR pAppGUID);
	bool GetAppTooltipInfo (PCTSTR pAppGUID, CString& text, CString& icon);

	bool FindApp (PCTSTR pAppGUID, CString& strAppName);
	bool FindAppRequirments (PCTSTR pAppGUID, CStringList& depApps);
	bool FindAppDependants (PCTSTR pAppGUID, CStringList& depApps);

protected:
	///<summary>The AppSets parent element from the configuration file</summary>
	XmlElement m_eAppSets;
	///<summary>The Apps parent element from the configuration file</summary>
	XmlElement m_eApps;

	inline void LoadAppSetsNode () { LoadNode (m_eAppSets, APPSETS_ELEMENTNAME, IDS_ERRORAPPSETSNODE); }
	inline void LoadAppsNode () { LoadNode (m_eApps, APPS_ELEMENTNAME, IDS_ERRORAPPSNODE); }

};
